package com.firefly.admin.tripartite.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.firefly.admin.common.annotations.annotation.OperationLog;
import com.firefly.admin.common.enums.OperationModuleEnum;
import com.firefly.admin.common.enums.OperationTypeEnum;
import com.firefly.admin.common.vo.Result;
import com.firefly.admin.tripartite.entity.FyTripartiteWechatApplet;
import com.firefly.admin.tripartite.service.FyTripartiteWechatAppletService;
import com.firefly.admin.tripartite.vo.WechatAppletQueryVo;
import com.firefly.admin.tripartite.vo.WechatAppletStatusUpdateVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

@Api(tags = "第三方微信小程序接口API")
@RestController
@RequestMapping("/tripartite/wechat/applet")
public class FyTripartiteWechatAppletController {

    @Autowired
    private FyTripartiteWechatAppletService fyTripartiteWechatAppletService;

    /**
     * 分页查询第三方微信小程序接口
     *
     * @param wechatAppletQueryVo 分页查询参数
     * @return 分页列表
     */
    @ApiOperation(value = "分页查询第三方微信小程序接口", notes = "分页查询第三方微信小程序接口", httpMethod = "GET")
    @PreAuthorize(value = "hasAuthority('tripartite:wechat:applet')")
    @GetMapping("/list")
    public Result<Page<FyTripartiteWechatApplet>> getWechatAppletList(WechatAppletQueryVo wechatAppletQueryVo) {
        return fyTripartiteWechatAppletService.getWechatAppletList(wechatAppletQueryVo);
    }

    /**
     * 第三方微信小程序信息新增接口
     *
     * @param fyTripartiteWechatApplet 微信小程序信息
     * @return 操作结果
     */
    @ApiOperation(value = "第三方微信小程序信息新增接口", notes = "第三方微信小程序信息新增接口", httpMethod = "POST")
    @OperationLog(module = OperationModuleEnum.TRIPARTITE_MANAGE, operateType = OperationTypeEnum.WECHAT_APPLET_CONFIG, operateDesc = "第三方微信小程序新增")
    @PreAuthorize(value = "hasAuthority('tripartite:wechat:applet:add')")
    @PostMapping("/add")
    public Result<FyTripartiteWechatApplet> add(@RequestBody FyTripartiteWechatApplet fyTripartiteWechatApplet) {
        return fyTripartiteWechatAppletService.add(fyTripartiteWechatApplet);
    }

    /**
     * 第三方微信小程序信息编辑接口
     *
     * @param fyTripartiteWechatApplet 微信小程序信息
     * @return 操作结果
     */
    @ApiOperation(value = "第三方微信小程序信息编辑接口", notes = "第三方微信小程序信息编辑接口", httpMethod = "POST")
    @OperationLog(module = OperationModuleEnum.TRIPARTITE_MANAGE, operateType = OperationTypeEnum.WECHAT_APPLET_CONFIG, operateDesc = "第三方微信小程序编辑")
    @PreAuthorize(value = "hasAuthority('tripartite:wechat:applet:update')")
    @PostMapping("/update")
    public Result<FyTripartiteWechatApplet> update(@RequestBody FyTripartiteWechatApplet fyTripartiteWechatApplet) {
        return fyTripartiteWechatAppletService.update(fyTripartiteWechatApplet);
    }

    /**
     * 第三方微信小程序状态编辑接口
     *
     * @param wechatAppletStatusUpdateVo 状态信息
     * @return 操作结果
     */
    @ApiOperation(value = "第三方微信小程序状态编辑接口", notes = "第三方微信小程序状态编辑接口", httpMethod = "POST")
    @OperationLog(module = OperationModuleEnum.TRIPARTITE_MANAGE, operateType = OperationTypeEnum.WECHAT_APPLET_CONFIG, operateDesc = "第三方微信小程序修改状态")
    @PreAuthorize(value = "hasAuthority('tripartite:wechat:applet:update:status')")
    @PostMapping("/update/status")
    public Result<FyTripartiteWechatApplet> updateStatus(@RequestBody WechatAppletStatusUpdateVo wechatAppletStatusUpdateVo) {
        return fyTripartiteWechatAppletService.updateStatus(wechatAppletStatusUpdateVo);
    }

    /**
     * 第三方微信小程序信息删除接口
     *
     * @param appletId 微信小程序ID
     * @return 操作结果
     */
    @ApiOperation(value = "第三方微信小程序信息删除接口", notes = "第三方微信小程序信息删除接口", httpMethod = "POST")
    @OperationLog(module = OperationModuleEnum.TRIPARTITE_MANAGE, operateType = OperationTypeEnum.WECHAT_APPLET_CONFIG, operateDesc = "第三方微信小程序删除")
    @PreAuthorize(value = "hasAuthority('tripartite:wechat:applet:delete')")
    @PostMapping("/delete")
    public Result<String> delete(Long appletId) {
        return fyTripartiteWechatAppletService.delete(appletId);
    }

    /**
     * 第三方微信小程序APPID校验接口
     *
     * @param appId    微信小程序APPID
     * @param appletId 微信小程序ID
     * @return 校验结果
     */
    @ApiOperation(value = "第三方微信小程序APPID校验接口", notes = "第三方微信小程序APPID校验接口", httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "appId", required = true, value = "微信小程序APPID", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "appletId", required = true, value = "微信小程序ID", paramType = "query", dataType = "Long")
    })
    @GetMapping("/appid/check")
    public Result<String> appIdCheck(String appId, Long appletId) {
        return fyTripartiteWechatAppletService.appIdCheck(appId, appletId);
    }
}
